<?php
$this->Html->css('controllers/Abilities/admin.css?11', array('block' => 'stylesTop'));
$this->Html->script('controllers/Abilities/admin.js?11', array('block' => 'scriptBottom'));
$this->Html->script('controllers/Abilities/createCertification.js?3', array('block' => 'scriptBottom'));
$this->Html->script('controllers/Abilities/destroyCertification.js?2', array('block' => 'scriptBottom'));
$this->Html->script('vendors/pictonic/pictonic.min.js?1', array('block' => 'scriptBottom'));
$appBosch->crud = $this->TioCachas->urlsCRUD($appBosch->teamId, $appBosch->lineId, $appBosch->userId);
$appBosch->urlCreateCertification = $this->Html->url(array('action' => 'createCertification'));
$appBosch->urlDestroyCertification = $this->Html->url(array('action' => 'destroyCertification'));
$appBosch->urlWorkstationConfig = $this->Html->url(array('controller' => 'WorkstationsConfigs', 'action' => 'getByWorkstation'));
$appBosch->urlUser = $this->Html->url(array('action' => 'user'));
$appBosch->urlSurvey = $this->Html->url(array('controller' => 'Survey', 'action' => 'apply'));
$appBosch->urlResumenTeam = $this->Html->url(array('controller' => 'TeamUsers', 'action' => 'getResume', $appBosch->teamId, $appBosch->lineId));
$appBosch->urlThemeOK = $this->Html->url(array('controller' => 'CertificationDetails', 'action' => 'getOkByUserAndLineAndType'));
$appBosch->urlThemeNOK = $this->Html->url(array('controller' => 'CertificationDetails', 'action' => 'getNokByUserAndLineAndType'));
$appBosch->urlAddEvaluation = $this->Html->url(array('controller' => 'Evaluations', 'action' => 'add'));
$appBosch->urlAddEvaluation = $this->Html->url(array('controller' => 'Evaluations', 'action' => 'add'));
$appBosch->urlPermissions = $this->Html->url(array('controller' => 'Users', 'action' => 'getSessionPermissions'));
?>
    <!--<script id="prepTemplate" type="text/x-kendo-template">
        # if(type === 2){ #
        <div class='prep-pie icon-pie'></div>
        # }else{ #
        <div class='prep-pie'></div>
        # } #
    </script>-->
    <!--<script id="objDerTemplate" type="text/x-kendo-template">
        # if(objInd < 25){ #
        <div class='obj-der icon-geo-cir-grid'></div>
        # }else if(objInd < 50){ #
        <div class='obj-der icon-pie2-2'></div>
        # }else if(objInd < 75){ #
        <div class='obj-der icon-pie2-4'></div>
        # }else if(objInd < 100){ #
        <div class='obj-der icon-pie2-6'></div>
        # } else { #
        <div class='obj-der icon-pie'></div>
        # } #
    </script>-->
    <!--<script id="titCambios" type="text/x-kendo-template">
    <div class="tituloCambios">
<?php echo __('Registro de Cambios'); ?>
    </div>
</script>-->
    <div id="imageable">
        <div id="ab-header">
            <table class="col-lg-12">
                <tr>
                    <td class="borde w200"><?php echo $this->Html->image('bosch-logo.png', array('width' => '130px')); ?></td>
                    <td class="borde f13"><?php echo $appBosch->hd['title']; ?></td>
                    <td class="borde f1"><?php echo $appBosch->hd['edition'] . ' ' . __('Edición'); ?></td>
                    <td class="borde f1"><?php echo __('Pagina 1/1'); ?></td>
                    <td class="borde">
                        <div class="f8 fecha"><?php echo __('Fecha de Emisión'); ?></div>
                        <div class="f8 fecha"><?php echo $appBosch->hd['emision_date']; ?></div>
                    </td>
                    <td class="borde">
                        <div class="f8 fecha"><?php echo __('Fecha de Revisión'); ?></div>
                        <div class="f8 fecha"><?php echo $appBosch->hd['revision_date']; ?></div>
                    </td>
                </tr>
                <tr class="borde h30">
                    <td class="borde f1"><?php echo $appBosch->hd['department'] ?></td>
                    <td class="borde f11"><?php echo $appBosch->hd['subtitle'] ?></td>
                    <td class="borde" colspan="2">
                        <div class="f1"><?php echo __('Autor: ') . ' ' . $appBosch->hd['author']; ?></div>
                        <div class="f1"><?php echo $appBosch->hd['author_department'] ?></div>
                    </td>
                    <td class="borde">
                        <div class="f9"><?php echo __('Tel') . ':' ?></div>
                        <div class="f9"><?php echo $appBosch->hd['author_number'] . ' ' . __('Ext.') . ' ' . $appBosch->hd['author_extension']; ?></div>
                    </td>
                </tr>
            </table>
            <div class="col-lg-12 config-line">
                <div class='text-left'>
                    <i class="fa fa-square" style='color: #f00;'></i>
                    <?php echo __('En entrenamiento'); ?>
                </div>
                <?php foreach ($appBosch->categories as $category) : ?>
                    <div class="categorization text-left" data-id="<?php echo $category['id']; ?>"
                         data-test_name="<?php echo $category['name']; ?>"
                         data-certifications="<?php echo $category['certifications']; ?>"
                         data-requiresApproval="<?php echo $category['requires_approval']; ?>"
                         data-lowerlimit="<?php echo $category['lower_limit']; ?>">
                        <i class='fa <?php echo $category['icon']; ?>'
                           style='color: <?php echo $category['colour']; ?>'></i>
                        <?php echo $category['name']; ?>
                    </div>
                <?php endforeach; ?>
                <span id="exportButton" class="k-button k-primary"><?php echo __('Exportar'); ?></span>
                <span id="summaryButton" class="k-button k-primary"><?php echo __('Resumen'); ?></span>
                <div class="categorization text-rigth"><?php echo $appBosch->description; ?></div>
                <div class="aProd"><?php echo __('Área productiva:'); ?></div>
            </div>
        </div>
        <div id="grid" class="abgrid"></div>
        <cite>
            <?php echo __('La fecha indicada en la matriz de habilidad es la vigencia de certificacion. '); ?>
        </cite>
        <p class="printInfo">
            <?php
                $dateS = date('d-m-Y H:i:s');
                echo __('Impreso por ') . $authUser['full_name'] . __(' en ') . $dateS . __(' desde ') . $_SERVER['REMOTE_ADDR'];
            ?>
        </p>
    </div>

    <div id="wndMH">
        <form id="formSaveCertification" role="form" method="post"
              action="<?php echo $this->Html->url(array('controller' => 'Abilities', 'action' => 'saveCertification')); ?>">
        </form>
    </div>

    <div id="wndCreateCertification" class="hidden">
        <form role="form" method="post"
              action="<?php echo $this->Html->url(array('controller' => 'Abilities', 'action' => 'createCertification')); ?>">
            <div style="margin-bottom: 10px;">
                <label for="w1"><?php echo __('Operación'); ?></label>
                <input id="w1" name="wId" class="workstations" value="#= workstation #" readonly="readonly"/>
            </div>
            <div style="margin-bottom: 10px;">
                <label for="w2"><?php echo __('Asociado'); ?></label>
                <input id="w2" name="uId" class="users" value="#= user #" readonly="readonly"/>
            </div>
            <div style="margin-bottom: 10px;">
                <label for="w3"><?php echo __('Fecha inicio'); ?></label>
                <input id="w3" name="cStart" class="cStart"/>
            </div>
            <div style="margin-bottom: 10px;">
                <label for="w4"><?php echo __('Fecha límite'); ?></label>
                <input id="w4" name="cEnd" class="cEnd"/>
                <cite>
                    <strong><?php echo __('?'); ?></strong>
                </cite>
            </div>
            <div class="alert alert-info">
                <?php
                echo __('Al dar clic en Iniciar proceso de certificación usted afirma '
                    . 'que reviso que el asociado cubre todos los requisitos previos '
                    . 'necesarios y demás procesos que la normatividad vigente solicita.');
                ?>
            </div>
            <div>
                <i class="fa fa-refresh fa-spin pull-right" id='loadingCreateCertitication'></i>
                <button type="button" class="pull-right btn k-primary" id="createCertification">
                    <?php echo __('Iniciar proceso de certificación'); ?>
                </button>
            </div>
        </form>
    </div>

    <div id="wndDestroyCertification" class='hidden'>
        <div class="alert alert-info">
            <?php echo __('Al dar clic en el botón eliminar usted acepta que después de realizar un análisis previo encontró motivos que fundamentan la eliminación de la certificación'); ?>
        </div>
        <label
            for="motivoEliminacion"><?php echo __('¿Cuál es el motivo por el cual elimina esta certificación?'); ?></label>
        <textarea name='comment' id="motivoEliminacion" style='width:95%'></textarea>
        <br/>
        <br/>
        <button type='button' class='btn btn-primary pull-right'>
            <?php echo __('Eliminar'); ?>
        </button>
        <i class="fa fa-spin fa-refresh pull-right hidden"></i>
    </div>

    <script id="templateTraining" type="text/kendo-template">
        <input type="hidden" name="cId" value="#=cId#"/>
        <input type="hidden" name="wId" value="#=wId#"/>
        <input type="hidden" name="uId" value="#=uId#"/>
        <div style="margin-bottom: 10px;">
            <label for='tt1'><?php echo __('Operación'); ?></label>
            <input id='tt1' class="workstations" value="#= wId #" readonly='readonly'/>
        </div>
        <div style="margin-bottom: 10px;">
            <label for='tt2'><?php echo __('Usuario'); ?></label>
            <input id='tt2' class="users" value="#= uId #" readonly='readonly'/>
        </div>
        <div style="margin-bottom: 10px;">
            <label for='tt3'><?php echo __('Iniciar certificación'); ?></label>
            <input id='tt3' name="cStart" class="cStart" readonly='readonly'/>
        </div>
        <div style="margin-bottom: 10px;">
            <label for='tt4'><?php echo __('Fin del proceso'); ?></label>
            <input id='tt4' name="cEnd" class="cEnd" readonly='readonly'/>
        </div>
        <div class="workstationsConfigs">
        </div>
        #if(cTraining == '0'){#
        <div style="margin-bottom: 10px;">
            <label for='tt5'><?php echo __('Vigencia'); ?></label>
            <input id='tt5' name="cLife" class="cLife" readonly='readonly'/>
        </div>
        #}#
        #if(appBosch.jsPermissions.crud.update===true){#
        <button type="button" class="pull-right btn k-primary" id="saveCertification">
            <i class="fa fa-check"></i>
            <?php echo __('Guardar'); ?>
        </button>
        #}#
    </script>

    <script id="templateConfigs" type="text/kendo-template">
        #
        var strDate = '';
        if(certification_detail_date !== null){
        var strDate = kendo.toString(new Date(certification_detail_date.replace(/-/g, "/")), 'd');
        }
        #
        <div style="margin-bottom: 10px;" class="detail">
            <label data-id="#=workstation_config_id#" data-minimum-qualification="#=workstation_config_qualification#">
                #=workstation_config_name#
            </label>
            <input data-min-qualification="#=workstation_config_qualification#"
                   value="#=certification_detail_qualification#"
                   name="details[#=workstation_config_id#][qualification]" for="details[#=workstation_config_id#][date]"
                   class="kendoNumeric" type="number" style="width: 65px;">
            <input name="details[#=workstation_config_id#][date]" for="details[#=workstation_config_id#][qualification]"
                   value="#=strDate#" class="kendoDatePicker"/>
            <input type="hidden" name="details[#=workstation_config_id#][id]"
                   value="#if(certification_detail_id !== null){##=certification_detail_id##}#"/>
            <i class="fa fa-check hidden"></i>
            <i class="fa fa-times hidden"></i>
        </div>
    </script>

    <script id="templateLinks" type="text/kendo-template">
        #
        var wcId = target.data('id');
        var minimumQualification = target.data('minimumQualification');
        var links = [];
        appBosch.links.forEach(function(link){
        if(link.id === wcId){
        links.push(link);
        }
        });
        #
        <div class="links">
            <p>
                <?php echo __('Calificación mínima requerida'); ?>: <strong>#=minimumQualification#</strong>
            </p>
            #if(links.length>0){#
            <p><?php echo __('La calificación depende de los siguientes criterios'); ?></p>
            <ul>
                #
                links.forEach(function(link){
                if(link.id === wcId){#
                <li>
                    #=link.line# - #=link.workstation# - #=link.workstationConfig#
                </li>
                #}
                });
                #
            </ul>
            #}#
        </div>
    </script>

    <script id="rowTemplateLinks" type="text/kendo-template">
        <tr>
            <td>#=uCurp#</td>
            <td>#=uNomina#</td>
            <td>#=uFullName#</td>
            <td>#=wcName#</td>
            <td class="ok" data-user-id='#=uId#' data-line-id="#=lId#" data-wc-name="#=wcName#">#=ok#</td>
            <td class="nok" data-user-id='#=uId#' data-line-id="#=lId#" data-wc-name="#=wcName#">#=nok#</td>
        </tr>
    </script>

    <script id="templateLevels" type="text/kendo-template">
        <table class="table table-bordered table-condensed table-hover table-striped">
            <thead>
            <tr>
                <th><?php echo __('Nivel actual'); ?></th>
                #if(next['cat.name'] !== undefined){#
                <th><?php echo __('Nivel objetivo'); ?></th>
                #}#
            </tr>
            </thead>
            <tbody>
            <tr>
                <td class="current">
                    <ul>
                        <li>
                            #=current.name#
                            <i class="fa #=current.icon#" style="color:#=current.colour#"></i>
                        </li>
                        <li>
                            #=current.certifications#&nbsp;<?php echo __('certificaciones requeridas'); ?>
                        </li>
                        <li>
                            #=certifications#&nbsp;<?php echo __('certificaciones logradas'); ?>
                            <i class="fa fa-check success"></i>
                        </li>
                        #if(test !==null){#
                        <li>
                            <?php echo __('curso'); ?>&nbsp;#=test['name']#&nbsp;<?php echo __('requerido'); ?>
                            <i class="fa fa-check success"></i>
                        </li>
                        #}#
                        <li>
                            <?php echo __('Límite de días: Mínimo'); ?>
                            :&nbsp;#=current['lower_limit']#&nbsp;
                            #if(current['daysCert'] == '1'){#
                            <i class="fa fa-check success"></i>
                            #}#
                        </li>
                        #if(current['requires_approval'] == '1'){#
                        <li>
                            <?php echo __('Requiere aprobación'); ?>
                        </li>
                        #}#
                    </ul>
                </td>
                #if(next['cat.name'] !== undefined){#
                <td class="next">
                    <ul>
                        <li>
                            #=next['cat.name']#
                            <i class="fa #=next['cat.icon']#" style="color:#=next['cat.colour']#"></i>
                        </li>
                        <li>
                            #=next['cat.certifications']#&nbsp;<?php echo __('certificaciones requeridas'); ?>
                        </li>
                        <li>
                            #
                            var x = (next['cat.certifications']-certifications) < 0 ? 0 :
                            next['cat.certifications']-current.certifications;
                            #
                            #=x#&nbsp;<?php echo __('certificaciones faltantes'); ?>
                            #if(x === 0){#
                            <i class="fa fa-check success"></i>
                            #}#
                        </li>
                        <li>
                            <?php echo __('curso'); ?>
                            &nbsp;#=next['t.name']#&nbsp;<?php echo __('requerido'); ?>
                            #if(next['0.evaluationSuccess']==='1'){#
                            <i class="fa fa-check success"></i>
                            #}else{#
                            <br/>
                            <input type="number" value="" id="qualificationAttempt"/>
                            <input type="date" value="" id="dateAttempt"/>
                            <button type="button" class="btn btn-primary attempt">
                                <?php echo __('Guardar intento'); ?>
                                <i class="fa fa-refresh fa-spin hidden"></i>
                            </button>
                            #}#
                        </li>
                        #if(next['cat.requires_approval'] == '1'){#
                        <li>
                            <?php echo __('Requiere aprobación'); ?>
                        </li>
                        #}#
                    </ul>
                </td>
                #}#
            </tr>
            </tbody>
        </table>
    </script>

    <script id="templateCategories" type="text/kendo-template">
        <table class="table table-bordered table-condensed">
            <tbody>
            <tr>
                <td><?php echo __('Certificaciones requeridas') ?></td>
                <td>
                    #if(target.data('certifications') == '0'){#
                    <?php echo __('Ninguna'); ?>
                    #}else{#
                    #=target.data('certifications')#
                    #}#
                </td>
            </tr>
            <tr>
                <td><?php echo __('Curso requerido') ?></td>
                <td>
                    #if(target.data('test_name') == ''){#
                    <?php echo __('Ninguno'); ?>
                    #}else{#
                    #=target.data('test_name')#
                </td>
                #}#
            </tr>
            <tr>
                <td><?php echo __('Requiere aprobación'); ?></td>
                <td>
                    #if(target.data('requiresapproval') == '1'){#
                    <i class="fa fa-check"></i>
                    #}#
                </td>
            </tr>
            <tr>
                <td><?php echo __('Mínimo de días'); ?></td>
                <td>#=target.data('lowerlimit')# días</td>
            </tr>
            </tbody>
        </table>
    </script>

    <script id='templateProgress' type="text/kendo-template">

    </script>

    <script id="templateFoto" type="text/kendo-template">
        # var path = '<?php echo $this->Html->url(array('controller' => 'Kardex', 'action' => 'index')); ?>/index'; #
        <a href="#=path#/#=unm#" target="_blank">
            <?php echo $this->Html->image('workers-mini/#=unm#.jpg', array('class' => 'workerMini')); ?>
        </a>
    </script>

    <script id="templateLinkNomina" type="text/kendo-template">
        # var path = '<?php echo $this->Html->url(array('controller' => 'Kardex', 'action' => 'index')); ?>/index'; #
        <a class="#=leader#" href="#=path#/#=unm#" target="_blank">#=unm#</a>
    </script>

    <script id="templateLinkNombre" type="text/kendo-template">
        # var path = '<?php echo $this->Html->url(array('controller' => 'Kardex', 'action' => 'index')); ?>/index'; #
        <a class="#=leader#" href="#=path#/#=unm#" target="_blank">#=un#</a>
        <i class="#=appBosch.categories[l].icon#" style="color:#=appBosch.categories[l].colour# !important;"></i>
    </script>

    <script id="templateSummary" type="text/kendo-template">
        <table class="table table-bordered table-striped">
            <tbody>
                <tr>
                    <td class="vertical-header"><?php echo __('Asociados'); ?></td>
                    <td>#=summary.asoc#</td>
                </tr>
                <tr>
                    <td class="vertical-header"><?php echo __('Estaciones'); ?></td>
                    <td>#=summary.wStations#</td>
                </tr>
                <tr>
                    <td class="vertical-header"><?php echo __('Certificaciones exitosas'); ?></td>
                    <td>#=summary.cE#</td>
                </tr>
                <tr>
                    <td class="vertical-header"><?php echo __('Certificaciones en entrenamientos'); ?></td>
                    <td>#=summary.t#</td>
                </tr>
                # for(var prop in summary) {
                    if (prop !== 'asoc' && prop !== 'wStations' && prop !== 'cE' && prop !== 't') { #
                        <tr>
                            <td class="vertical-header"><?php echo __('Asociados en '); ?>#=prop#</td>
                            <td>#=summary[prop]#</td>
                        </tr>
                    # }
                } #
            </tbody>
        </table>
    </script>

    <div id="wndUser" class="hidden">
        <div class="levels"></div>
        <table class="table table-bordered table-condensed table-hover table-striped" id="tableResumen">
            <thead>
            <tr>
                <th><?php echo __('CURP'); ?></th>
                <th><?php echo __('Nomina'); ?></th>
                <th><?php echo __('Asociado'); ?></th>
                <th><?php echo __('Tema'); ?></th>
                <th><?php echo __('OK'); ?></th>
                <th><?php echo __('NOK'); ?></th>
            </tr>
            </thead>
            <tbody></tbody>
        </table>
    </div>

    <div id='wndSurvey'></div>

<?php $this->start('jsVars'); ?>
    <script type="text/javascript">
        var appBosch = <?php echo json_encode($appBosch); ?>;
    </script>
<?php
$this->end();


